// pages/component/homes/accountbalance/accountbalance.js

var GlobalData = require('../../../../utils/GlobalData.js');
var dataManager = require('../../../../utils/dataManager.js');
Page({

  /**
   * 页面的初始数据   goBalanceDetail
   */
  data: {
    accountData: 0,
    balanceArr: [],
    arrlength: 0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示{{homeData.accountbalance}}
   */
  onShow: function () {
    dataManager.removeBtnObserver("accountbalance")

    if (GlobalData.homeData) {
      this.setData({
        accountData: GlobalData.homeData.accountbalance
      })
    }
    // GlobalData.BalanceDetail = GlobalData.clone(arr)
    if (GlobalData.BalanceDetail) {
      this.onComplete();
    }
  },

  onComplete: function () {
    var ar = [];
    if (GlobalData.BalanceDetail.length > 10) {
      ar = GlobalData.BalanceDetail.slice(0, 10);
    } else
      ar = GlobalData.BalanceDetail;
    for (let i = 0; i < ar.length; i++) {
      let amount = parseInt(ar[i].amount);
      let str = "" + ar[i].amount;
      if (amount > 0 && str.indexOf("+") < 0)
        ar[i].amount = "+" + ar[i].amount;
      ar[i].createtime = ar[i].createtime.replace('T', ' ');
      if (ar[i].remark == null) {
        ar[i].remark = " "
      }
      if (ar[i].remark.indexOf("</br>") > -1) {
        ar[i].remark = ar[i].remark.replace("</br>", "");
      }
    }
    this.data.arrlength = ar.length;
    this.setData({
      balanceArr: ar,
      arrlength: this.data.arrlength
    })

    /**判断是否有数据 */
    // if (ar.length == 0)
    //   this.data.haveData = true;

  },

  /**前往余额详情页面 */
  goBalanceDetail: function () {
    // pages/component/homes/help/homehelp/homehelp"



    dataManager.UseNavigateTo('../../homes/balancedetail/balancedetail', false);
  },
  /**前往充值 */
  goMoneyreCharge: function () {
    // pages/component/homes/help/homehelp/homehelp"
    dataManager.UseNavigateTo('../../homes/purchase/moneyrecharge/moneyrecharge', false);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})